package com.thread.domain.notify;

public class ExpressNotify {
	
	public final static String CITY="shanghai";
	
	private int km;  //快递运输里程数
	
	private String site; //快递到达地点
	
	public ExpressNotify() {
	}

	public ExpressNotify(int km, String site) {
		this.km = km;
		this.site = site;
	}
	
	
	public synchronized void changeSite() {
		this.site="beijing";
		notify();
	}
	
	public synchronized void changeKm() {
		this.km=101;
		notify(); //发出唤醒通知
	}
	
	public synchronized void waitKm() {
		while(this.km<=100) {
			try {
				wait();
				System.out.println("check km thread"+Thread.currentThread().getId()+"is wait");
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		System.out.println(Thread.currentThread().getId()+"change "+this.km);
	}
	
    public synchronized void waitSite() {
    	while(this.site.equals(CITY)) {
			try {
				wait();
				System.out.println("check site thread"+Thread.currentThread().getId()+"is wait");
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		System.out.println(Thread.currentThread().getId()+"change "+this.site);
	}
	

}
